package com.asset.manager.auth;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Sa-Token 配置
 */
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，校验规则为全部路由必须登录
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/user/login",  // 排除登录接口
                        // 排除 knife4j 相关接口
                        "/doc.html",     // knife4j 文档页面
                        "/webjars/**",    // knife4j 静态资源
                        "/v2/api-docs",   // API 文档JSON
                        "/swagger-resources/**",  // Swagger 资源
                        "/favicon.ico"    // 网站图标
                );
    }
}